<?php
/** require:
 *  __PHY_LIB
 */
require_once(__PHY_LIB . "/class/Item.class.php");

class Category extends Item {
/// definition and constructor ///
	function Category($id=0, $field="") {
		Query::Query();
		$this->cfgKeyField("id");
		$this->cfgAllField("id,name,title,parent_id");
		$this->cfgTable("unit_category");
		if ("" == $field || "*" == $field) {
			$this->cfgField($this->mAllField);
		}
		else {
			$this->cfgField($field);
		}
		if (0 < $id) {
			$this->cfgWhere($this->mKeyField . "=" . $id);
			$this->load();
		}
		else {
			$this->set($this->mKeyField, $id);
		}
	}

	function invalid() {
		if (!preg_match('/^\S{1,127}$/', $this->get('name'), $x)) {
			return 'title';
		}
		if (!preg_match('/^.{0,255}$/', $this->get('title'), $x)) {
			return 'url';
		}

		return false;
	}

} /// end class Category.


class CategoryList extends ItemList {
	/// definition and constructor ///
	function CategoryList($tablename=null) {
		ItemList::ItemList();
		$this->cfgClass("Category");
		$this->cfgKeyField("id");
		$this->cfgAllField("id,name,title,parent_id");
		$this->cfgTable(null == $tablename ? "unit_category" : $tablename);
	}

} /// end class CategoryList.
?>
